package com.chalk.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.chalk.model.Picture;
import com.chalk.dao.PictureDao;
import com.chalk.service.PictureService;

import com.chalk.util.MapUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author glq
 * @since 2020-12-19
 */

@Service
public class PictureServiceImpl extends ServiceImpl<PictureDao, Picture> implements PictureService {

    @Override
    public int addPicture(Picture entity) {
        return baseMapper.insert(entity);
    }

    @Override
    public int updatePicture(Picture entity) {
        return baseMapper.updateById(entity);
    }


    @Override
    public int deletePicture(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public Page<Picture> getPicturesForPage(Map<String, Object> map) {
        Integer page = MapUtil.getPage(map);
        Integer size = MapUtil.getSize(map);
        //构造器
        EntityWrapper<Picture> wrapper = new EntityWrapper<>();
        wrapper.eq("is_delete", 0);
        wrapper.eq("picture_type",1);
        //排序
        List<String> desc = new ArrayList<>();
        desc.add("create_time");
        Page<Picture> picturePage=new Page<>(page,size);
        picturePage.setDescs(desc);

        return selectPage(picturePage,wrapper);
    }
}
